package com.txby.wxyyApi.component.web;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.txby.wxyyApi.component.service.WrSysApiUserService;
import com.txby.wxyyApi.config.PropertySourceConfig;
import com.txby.wxyyApi.entity.WrSysApiUser;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.ehcache.CacheManager;

@RestController
@Api("用户功能")
public class WrSysApiUserController {
	private static Logger log = Logger.getLogger(WrSysApiUserController.class);
	@Autowired
	private CacheManager cacheManager;
	@Resource
	private PropertySourceConfig PC;
	@Resource
	private WrSysApiUserService udc;
//	@ApiIgnore
	@ApiOperation(value = "查询所有用户", notes = "查询所有用户")
	@GetMapping("/getUsers")
	public List<WrSysApiUser> getUsers() {
		System.out.println(cacheManager.getCache("alarmPileNumTime"));
		List<WrSysApiUser> users = udc.findAll(WrSysApiUser.class);
		log.debug("jacking--test");
		System.out.println(PC);
		return users;
	}
//	@ApiIgnore
	@ApiOperation(value = "保存用户", notes = "保存用户")
	@PostMapping(value = "/saveUser")
	public String saveUser(@RequestBody( required = true) WrSysApiUser user) {
		udc.saveObject(user);
		return "ok";
	}
//	@ApiIgnore
	@ApiOperation(value = "根据id查询用户", notes = "查询单用户")
	@GetMapping("/getUser/{id}")
	public WrSysApiUser getUser(@PathVariable("id") String id) {
		WrSysApiUser user = (WrSysApiUser) udc.findById(WrSysApiUser.class, id);
		return user;
	}
//	@ApiIgnore
	@ApiOperation(value = "新增用户", notes = "新增用户")
	@PostMapping("/add")
	public void save(WrSysApiUser user) {
		udc.saveObject(user);
	}
	@ApiOperation(value = "根据数据修改用户", notes = "修改用户")
	@PutMapping(value = "update")
	public void update(WrSysApiUser user) {
		udc.updateObject(user);
	}
	@ApiOperation(value = "根据id删除用户", notes = "删除用户")
	@DeleteMapping(value = "/delete/{id}")
	public void delete(@PathVariable("id") String id) {
		udc.deleteById(WrSysApiUser.class, id);
	}

}